package com.veng.springbootdemo.service;

import com.veng.springbootdemo.dao.UserInfoRepository;
import com.veng.springbootdemo.po.UserInfo;
import com.veng.springbootdemo.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserInfoServiceImp implements UserInfoService {
    @Autowired
    private UserInfoRepository userInfoRepository;
    @Override
    public UserInfo findUserInfoByUsername(String username) {
        return userInfoRepository.findByUsername(username);
    }

    @Override
    public List<UserInfoVo> findAll() {
        List<UserInfo> all = userInfoRepository.findAll();
        ArrayList<UserInfoVo> userInfoVos = new ArrayList<>();
        for (UserInfo userInfo : all) {
            String username = userInfo.getUsername();
            String name = userInfo.getName();
            UserInfoVo userInfoVo = new UserInfoVo();
            userInfoVo.setUsername(username);
            userInfoVo.setName(name);
            userInfoVos.add(userInfoVo);
        }
        return userInfoVos;
    }
}
